﻿<cfscript>
/** 
* Unit Advicer
* 
* @hint "Unit convert Advicer" 
*/ 

component 
	displayname="public.service.util.unitAdvice" 
	output=false 
	{
	
	/**
	* @hint "初始化对象"
	*/
	public public.service.util.unitAdvice function init() output=false {
		return this;
	}


	/**
	* @hint "显示文件大小的友好单位"
	* 
	* @fileByteLength "种子文件物理路径"
	*/
	public string function getFileSize( required numeric fileByteLength ) output=false {
		
		if ( fileByteLength gt 1000^10) {
			return numberFormat( arguments.fileByteLength / 1024^10 ) & " DB";
		}
		else if ( fileByteLength gt 1000^9 ) {
			return numberFormat( arguments.fileByteLength / 1024^9, "_.99" ) & " NB";
		}
		else if ( fileByteLength gt 1000^8 ) {
			return numberFormat( arguments.fileByteLength / 1024^8, "_.99" ) & " YB";
		}
		else if ( fileByteLength gt 1000^7 ) {
			return numberFormat( arguments.fileByteLength / 1024^7, "_.99" ) & " ZB";
		}
		else if ( fileByteLength gt 1000^6 ) {
			return numberFormat( arguments.fileByteLength / 1024^6, "_.99" ) & " EB";
		}
		else if ( fileByteLength gt 1000^5 ) {
			return numberFormat( arguments.fileByteLength / 1024^5, "_.99" ) & " PB";
		}
		else if ( fileByteLength gt 1000^4 ) {
			return numberFormat( arguments.fileByteLength / 1024^4, "_.99" ) & " TB";
		}
		else if ( fileByteLength gt 1000^3 ) {
			return numberFormat( arguments.fileByteLength / 1024^3, "_.99" ) & " GB";
		}
		else if ( fileByteLength gt 1000^2 ) {
			return numberFormat( arguments.fileByteLength / 1024^2, "_.99" ) & " MB";
		}
		else if ( fileByteLength gt 1000 ) {
			return numberFormat( arguments.fileByteLength / 1024, "_.99" ) & " KB";
		}
		else {
			return arguments.fileByteLength & " Byte";
		}
		
	}
	
}

</cfscript>